package com.example.todo;

import android.app.Activity;
import android.app.ActionBar;
import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.Spinner;
import android.os.Build;

public class FilterActivity extends Activity {

	public static String EXTRA_FILTER_NAME = "com.example.ToDo.NAME";
	public static String EXTRA_FILTER_CATEGORY = "com.example.ToDo.Category";
	public static String EXTRA_FILTER_SUBJECT = "com.example.ToDo.Subject";
	public static String EXTRA_FILTER_PROJECT = "com.example.ToDo.Project";
	public static String EXTRA_FILTER_DUEDATE = "com.example.ToDo.DueDate";
	public static String EXTRA_FILTER_Location = "com.example.ToDo.Location";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.fragment_filter);

		//Don't allow the keyboard to pup up when the page loads.
        this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); 
	}

// START NAVIGATION MENU CODE
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {

		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.filter, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}

	/**
	 * A placeholder fragment containing a simple view.
	 */
	public static class PlaceholderFragment extends Fragment {

		public PlaceholderFragment() {
		}

		@Override
		public View onCreateView(LayoutInflater inflater, ViewGroup container,
				Bundle savedInstanceState) {
			View rootView = inflater.inflate(R.layout.fragment_filter,
					container, false);
			return rootView;
		}
	}
// END NAVIGATION MENU CODE
	
	public void onClick_Search(View view){
		Intent intentSearch = new Intent(this, FilteredResultsActivity.class);
		
		//Get the category
		Spinner newCategory = (Spinner) findViewById(R.id.add_category);
		String category = newCategory.getSelectedItem().toString();
        intentSearch.putExtra(EXTRA_FILTER_CATEGORY, category);
        // Get the task name
        EditText filterTaskName = (EditText) findViewById(R.id.task_name);
		String name = filterTaskName.getText().toString();
        intentSearch.putExtra(EXTRA_FILTER_NAME,  name);
        // Get the task subject
        EditText filterSubject = (EditText) findViewById(R.id.new_subject);
        String subject = filterSubject.getText().toString();
        intentSearch.putExtra(EXTRA_FILTER_SUBJECT,  subject);        
        // Get the task project
        EditText filterProject = (EditText) findViewById(R.id.new_project);
        String project = filterProject.getText().toString();
        intentSearch.putExtra(EXTRA_FILTER_PROJECT,  project);        
        // Get the task due date
        EditText filterDueDate = (EditText) findViewById(R.id.new_date);
        String dueDate = filterDueDate.getText().toString();
        intentSearch.putExtra(EXTRA_FILTER_DUEDATE,  dueDate);        
        // Get the task location
        EditText filterlocation = (EditText) findViewById(R.id.new_location);
        String location = filterlocation.getText().toString();
        intentSearch.putExtra(EXTRA_FILTER_Location,  location);        
    	
        startActivity(intentSearch);
	}
	public void onClickClose(View view){
		//Close this activity and go to the main page.
    	Intent intent = new Intent(this, MainActivity.class);
    	startActivity(intent);
	}
}
